﻿using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfUsercontrol.Models;
using WpfUsercontrol.Models.TimeLines;
using WpfUsercontrol.Utils.Pdf;

namespace WpfUsercontrol
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private List<ItemModel> PullDownList = new List<ItemModel>();

        public MainWindow()
        {
            InitializeComponent();
            LoadInit();
        }

        private void LoadInit()
        {
            // 添加示例数据
            PullDownList.Add(new ItemModel { Id = "1", Name = "Apple" });
            PullDownList.Add(new ItemModel { Id = "2", Name = "Banana" });
            PullDownList.Add(new ItemModel { Id = "3", Name = "Orange" });
            PullDownList.Add(new ItemModel { Id = "4", Name = "Grape" });
            PullDownList.Add(new ItemModel { Id = "5", Name = "Watermelon" });
            PullDownList.Add(new ItemModel { Id = "6", Name = "Pineapple" });
            PullDownList.Add(new ItemModel { Id = "7", Name = "Strawberry" });
            PullDownList.Add(new ItemModel { Id = "8", Name = "Blueberry" });
            PullDownList.Add(new ItemModel { Id = "9", Name = "Raspberry" });
            PullDownList.Add(new ItemModel { Id = "10", Name = "Blackberry" });
            PullDownList.Add(new ItemModel { Id = "11", Name = "Peach" });
            PullDownList.Add(new ItemModel { Id = "12", Name = "Pear" });
            PullDownList.Add(new ItemModel { Id = "13", Name = "Mango" });
            PullDownList.Add(new ItemModel { Id = "14", Name = "Kiwi" });
            PullDownList.Add(new ItemModel { Id = "15", Name = "Cherry" });
            _PullDownQueryCombox.ItemList = PullDownList;
            _PullDownQueryCombox.CurrentItem = PullDownList[4];


            var timelineItems = new ObservableCollection<TimeLineItem>
            {
                new TimeLineItem
                {
                    Type = "功能",
                    Time = "2025-03-12 09:00",
                    Content = "新增用户管理模块",
                },
                new TimeLineItem
                {
                    Type = "修复",
                    Time = "2025-03-12 11:30",
                    Content = "解决登录页面闪退问题\n问题原因：空指针异常",
                },
                new TimeLineItem
                {
                    Type = "会议",
                    Time = "2025-03-12 14:00",
                    Content = "",
                }
            };
            // 设置最后一项标记
            if (timelineItems.Count > 0)
            {
                timelineItems.Last().IsLastItem = true;
            }

            VTimeLine.ItemsSource = timelineItems;
            MainListView.ItemsSource = timelineItems;

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(_PullDownQueryCombox.CurrentItem.Name);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            PdfHelper.CreatPdf("D:\\pdfdemo.pdf");
            MessageBox.Show("完成！");
        }

        private void TextBlock_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is TextBlock textBlock)
            {
                // 设置弹出框内容
                FullContentTextBlock.Text = textBlock.Text;

                // 获取鼠标相对于屏幕的位置
                Point mousePosition = e.GetPosition(this);
                Point screenPosition = PointToScreen(mousePosition);

                // 设置弹出框位置
                ContentPopup.Placement = PlacementMode.Absolute;
                ContentPopup.HorizontalOffset = screenPosition.X;
                ContentPopup.VerticalOffset = screenPosition.Y;

                // 显示弹出框
                ContentPopup.IsOpen = true;
            }
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            // 关闭弹出框
            ContentPopup.IsOpen = false;
        }

        private void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            // 复制内容到剪贴板
            Clipboard.SetText(FullContentTextBlock.Text);

            // 可选：显示复制成功的反馈
            var button = sender as System.Windows.Controls.Button;
            if (button != null)
            {
                button.Content = "已复制!";
                var timer = new System.Windows.Threading.DispatcherTimer
                {
                    Interval = System.TimeSpan.FromSeconds(1)
                };
                timer.Tick += (s, args) =>
                {
                    button.Content = "复制";
                    timer.Stop();
                };
                timer.Start();
            }
        }
    }
}